import GameManager from "./GameManager";


const { ccclass, property } = cc._decorator;

/** 地球产出 */
export enum EarthOut {
    Earth_earth,//地球
    Earth_People,//人
    Earth_Car,//汽车
    Earth_Copter,//直升机
    Earth_Airplane,//飞机
}

@ccclass
export default class GameData {

    private static _instance: GameData = null;
    public static get Instance(): GameData {
        if (!this._instance) {
            this._instance = new GameData();
        }
        return this._instance;
    }
    public static InitData() {
        this._instance = new GameData();
    }

    public GameScore: number = 0;//污染值
    public Money: number = 400;
    public increaseSpeed: number = 0;//每秒货币增加数量
    public increasemultiple: number = 1;//每秒货币增加倍数
    public NodeData: number[] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];//地球每个节点上建筑的id；

    public EarthOuts: cc.Node[][] = [[], [], [], [], []];//记录当前地球产出的产物

    //===========常量=============//
    public static EarthOut_thresholdvalue: number[][] = [
        [600, 1400, 1800, 3000, 5500, 8000, 12000, 17000, 25000, 35000],//地球阈值(污染阈值（暂定）)
        [300, 350, 400, 450, 500, 600, 700, 800, 900, 1000, 1100, 1300, 1500, 1700, 2000, 2300, 2600, 2900, 3200,
            3500, 3900, 4300, 4700, 5100, 5500, 6000, 6600, 7200, 8000, 8800, 9600, 10400, 11000, 12000, 13000,
            14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 23000, 25000, 27000, 30000],//人口阈值（暂定）
        [800, 900, 1100, 1500, 2100, 3500, 5000, 7000, 9000, 13000, 17500, 23000, 27000, 32000],//汽车阈值（暂定）
        [3000, 5000, 8000, 12000, 16000, 22000, 27000, 32000],//直升机阈值（暂定）
        [5000, 12000, 20000, 30000]//飞机阈值（暂定）
    ]

    public static architecture_contaminate: number[] = [0, 0, 20, 35, 70, 120, 180, 300, 500, 1000];//各型号建筑污染值（暂定）
    public static architecture_production: number[] = [0, 1, 3, 6, 18, 28, 70, 130, 280, 550];//各型号建筑产钱速度（暂定）

    //地球变化背景色
    public static BgColor: cc.Color[] = [cc.color(255, 255, 255), cc.color(255, 255, 255), cc.color(255, 255, 255), cc.color(255, 255, 255),
    cc.color(255, 224, 224), cc.color(255, 189, 189), cc.color(255, 155, 155), cc.color(255, 117, 117), cc.color(155, 92, 92),
    cc.color(208, 126, 126), cc.color(130, 95, 95)];


    public static BuildName: string[] = ["Build1", "Build100", "Build500", "Build1K", "Build5K", "Build10K", "Build50K"
        , "Build100K", "Build500K", "Build1B"];//房子名字
    public static BuildPrice: number[] = [0, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000];//房子价格

    //获取当前值下的阈值(参数是对应常量数组)
    public static Get_thresholdvalue(architectureType: EarthOut): number {
        let thresholdvalue: number = 0;
        for (let i = 0; i < GameData.EarthOut_thresholdvalue[architectureType].length; i++) {
            if (GameData.Instance.GameScore >= GameData.EarthOut_thresholdvalue[architectureType][i]) {
                thresholdvalue = i + 1;
            } else {
                break;
            }
        }
        return thresholdvalue;
    }

    //获取当前状态下每秒产钱速度
    public static Getproduction(): number {
        let production: number = 0;
        for (let i = 0; i < GameData.Instance.NodeData.length; i++) {
            production += GameData.architecture_production[GameData.Instance.NodeData[i]];
        }
        return production;
    }
    //获取当前状态下污染
    public static Getcontaminate(): number {
        let contaminate: number = 0;
        for (let i = 0; i < GameData.Instance.NodeData.length; i++) {
            contaminate += GameData.architecture_contaminate[GameData.Instance.NodeData[i]];
        }
        return contaminate;
    }
}
